package com.probox.modules.controller.customer;


import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.entity.domain.customer.CustomerLabel;
import com.probox.common.entity.service.customer.ICustomerLabelService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/customer/label")
public class CustomerLabelController  extends BaseController {


    @Autowired
    private ICustomerLabelService customerLabelService;


    /**
     * 查询客户标签列表
     */
    @GetMapping("/list")
    public AjaxResult list(CustomerLabel customerLabel) {
        List<CustomerLabel> list = customerLabelService.queryList(customerLabel);
        return AjaxResult.success(list);
    }

    /**
     * 查询该等级的类别
     */
    @GetMapping("/depthlist/{depth}")
    public AjaxResult depthlist(@PathVariable("depth") String depth) {
        List<CustomerLabel> categoryDepthList = customerLabelService.getCategoryDepthList(depth, SecurityUtils.getPlatformId());
        return AjaxResult.success(categoryDepthList);
    }

    /**
     * 获取菜单下拉树列表
     */
    @GetMapping("/selectOptions")
    public AjaxResult selectOptions()
    {
        return AjaxResult.success(customerLabelService.selectOptionList());
    }

    /**
     * 导出客户标签列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerLabel customerLabel) throws IOException {
        List<CustomerLabel> list = customerLabelService.queryList(customerLabel);
        ExcelUtil<CustomerLabel> util = new ExcelUtil<CustomerLabel>(CustomerLabel.class);
        util.exportExcel(response, list, "客户标签数据");
    }

    /**
     */
    @GetMapping(value = "/{categoryUid}")
    public AjaxResult getInfo(@PathVariable("categoryUid") Long categoryUid) {
        return AjaxResult.success(customerLabelService.selectCustomerLabelById(categoryUid));
    }

    /**
     * 新增客户标签
     */
    @PostMapping
    public AjaxResult add(@RequestBody CustomerLabel customerLabel) {
        return toAjax(customerLabelService.insertProductCategory(customerLabel));
    }

    /**
     * 修改客户标签
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerLabel customerLabel) {
        return toAjax(customerLabelService.updateProductCategory(customerLabel));
    }

    /**
     * 修改客户标签状态
     */
    @PutMapping("/updateCategoryStatus")
    public AjaxResult changeStatus(@RequestBody CustomerLabel customerLabel) {
        return toAjax(customerLabelService.updateCategoryStatus(customerLabel));
    }

    /**
     * 删除客户标签
     */
    @DeleteMapping("/{categoryUids}")
    public AjaxResult remove(@PathVariable Long[] categoryUids) {
        return toAjax(customerLabelService.deleteProductCategoryByIds(categoryUids));
    }


}
